/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.core.figures.NodeFigure;
import com.cea.papyrus.core.figures.NoteFigure;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * This edit part handles stereotype property values display in diagrams.
 */
public class StereotypePropertiesListEditPart extends GraphNodeWithSemanticEditPart {
	
	/**
	 * Creates a new StereotypePropertiesListEditPart 
	 * @param graphNode parent of the graph node controlled by this edit part
	 * @param modelManager manager in charge of models, graphic and domain
	 */
	public StereotypePropertiesListEditPart(GraphNode graphNode, ModelManager modelManager){
		super(graphNode, modelManager);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void refreshVisuals() {
		Debug.debug(this, "refreshvisuals", channel);

		Dimension size = getGraphNode().getSize();
		Point p = getGraphNode().getPosition();
		Rectangle r = new Rectangle(p ,size);

		IFigure fig = getFigure();

		// if fig is a stereotype figure
		if (!(fig instanceof NoteFigure)) {
			IconFigure icf = (IconFigure) getFigure();
			//icf.setName(getUmlElement().getBody());
		} else {
			//org.eclipse.uml2.uml.Comment currentComment = (org.eclipse.uml2.uml.Comment) getUmlElement();
			//com.cea.utils.Element currentElement = new com.cea.utils.Element(getUmlElement());
			
			// Retrieve current class and figure
			NoteFigure f = (NoteFigure) fig; //get Class figure
			f.setComment("STEREOTYPE PROPERTY VALUES"); //set the content of the figure
			
			// if fig is a ClassFigure
			((NodeFigure) fig).refreshColors(getGraphNode());
			// set additionnal graphical parameter
			f.setfigureFont(getGraphNode().getFontFamily());
			f.setFontSize((getGraphNode().getFontSize()));
			f.setLineThickness((getGraphNode().getLineThickness()));
			
			//((NodeFigure) fig).refreshPresentation(getPresentation(), (Element) currentComment);
			//boolean hasIcon  = currentElement.hasIcon();
			//boolean hasShape = currentElement.hasShape();
			//f.refreshStereotypes(currentElement.getStereotypes(), getPresentation(), hasIcon, hasShape);
		}

		((GraphicalEditPart) getParent()).setLayoutConstraint(
				this,
				fig,
				r);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IFigure createFigure() {
		// Force initialization of the manager when figure has changed
		//  Try to get figure from ContainerWithSemanticEditPart
		IFigure fig = super.createFigure();
		if (fig != null) {
			return fig;
		}
		return new NoteFigure();			
	}
	
	/**
	 * Always returns <code>null</code>, as this edit part is not directly link to a specific UML element.
	 */
	@Override
	public org.eclipse.uml2.uml.Comment getUmlElement() {
		return null;
	}
	
	/**
	 * No direct edition by default for this edit part. this method always returns <code>false</code>.
	 */
	@Override
	protected boolean checkDefaultEdition() {
		return false;
	}
	
//	/*
//	 * (non-Javadoc)
//	 * @see com.cea.papyrus.core.classdiagram.editpart.CommentEditPart#initLabelControlerManager()
//	 */
//	/**
//	 * 
//	 */
//	protected void initLabelControlerManager() {
//	}
//
//	
//	/*
//	 * (non-Javadoc)
//	 * @see com.cea.papyrus.core.classdiagram.editpart.CommentEditPart#performDirectEdit(org.eclipse.gef.Request)
//	 */
//	/**
//	 * 
//	 * 
//	 * @param req 
//	 */
//	public void performDirectEdit(Request req) {
//    	// no direct editing is allowed here
//    }
}
